﻿using System;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// 控件 PanelCtl 属性的XML转换
    /// </summary>
    public class PanelCtlPropertyXML : CtrlContainerPropertyXML
    {
        /// <summary>
        /// 控件 PanelCtl 属性的XML转换
        /// </summary>
        /// <param name="panelCtl"></param>
        public PanelCtlPropertyXML(PanelCtl panelCtl)
            : base(panelCtl)
        {
            _panelCtl = panelCtl;
        }

        private PanelCtl _panelCtl = null;

        public override string ToXML()
        {
            return "<AutoScroll>" + this.BoolToString(_panelCtl.AutoScroll) + "</AutoScroll>" +
                      "<BackgroundImage>" + ConvertImageToString(_panelCtl.BackgroundImage) + "</BackgroundImage>" +
                      "<BackgroundImageLayout>" + ((int)_panelCtl.BackgroundImageLayout).ToString() + "</BackgroundImageLayout>" +
                      "<Base>" + base.ToXML() + "</Base>";
        }

        public override void FromXML(System.Xml.XmlNodeList xns)
        {
            if (xns != null && xns.Count > 0)
            {
                foreach (System.Xml.XmlNode XN in xns)
                {
                    switch (XN.Name.ToLower())
                    {
                        case "autoscroll":
                            _panelCtl.AutoScroll = StringToBool(XN.InnerText);
                            break;

                        case "backgroundimage":
                            _panelCtl.BackgroundImage = XN.InnerText.Length > 0 ? ConvertStringToImage(XN.InnerText) : null;
                            break;

                        case "backgroundimagelayout":
                            _panelCtl.BackgroundImageLayout = (System.Windows.Forms.ImageLayout)Convert.ToInt32(XN.InnerText);
                            break;

                        case "base":
                            base.FromXML(XN.ChildNodes);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
}